<template>
	<view class="pages">
		<view class="List">
			<view class="my">
				<view class="left">
					<view
						style="display: flex;justify-content: space-between;margin-bottom: 3vw;border-bottom: 1rpx solid silver;">
						<view class="showName" style="font-size: 40rpx;margin-bottom: 20rpx;font-weight: 700;">
							{{data.formUser}}
						</view>
					</view>
					<view style="display: flex;justify-content: space-between;">
						<view>
							<image :src="data.img" style="width: 20vw;height: 20vw;margin-left: 2vw;" mode=""></image>
							<view class="showPhone">
								{{data.foodName}}
							</view>
						</view>
						<view>
							<view class="show" style="padding-left:100rpx;margin-bottom: 5vw; ">
								<u-number-box v-model="quantity" @change="valChange" :min="1" :max="100"></u-number-box>
							</view>
							<view class="show" style="margin-bottom: 5vw;display: flex;flex-direction:row-reverse">
								单价:￥{{data.foodPrice}}元,实付:￥{{shopTotalPrice}}
							</view>
							<view @click="one"
								style="border: 1rpx solid silver;text-align: center;width: 20vw;height: 8vw;line-height: 8vw;margin-left: 23vw;">
								确认付款</view>
						</view>
					</view>
				</view>
			</view>
			<u-toast ref="uToast"></u-toast>
		</view>
	</view>
</template>

<script>
	import {
		moneyPerson,
		postShopPersonList,
		guard
	} from "@/ww.js"
	import {
		toast
	} from "@/common.js"
	import {
		getwordOrder
	} from "@/tool/index.js"
	export default {
		data() {
			return {
				show: false,
				data: '',
				quantity: 1,
				shopTotalPrice: '',
				money: '',
				areaPer: '', //个人地址
				phonePer: '' //用户电话
			};
		},
		onLoad(e) {
			guard('../../login/login')
			if (uni.getStorageSync('token').token) {
				this.data = JSON.parse(decodeURIComponent(e.item))
				this.shopTotalPrice = this.data.foodPrice
				moneyPerson({
					username: uni.getStorageSync("userInfo").username
				}).then(res => {
					this.money = res.data.money
				})
			}
		},
		methods: {
			valChange(e) {
				this.shopTotalPrice = this.data.foodPrice * e.value
			},
			one() {
				if (this.shopTotalPrice >= this.money) {
					toast('余额不足')
				} else {
					let time = new Date()
					var year = time.getFullYear(),
						month = ("0" + (time.getMonth() + 1)).slice(-2),
						date = ("0" + time.getDate()).slice(-2),
						hour = ("0" + time.getHours()).slice(-2),
						minute = ("0" + time.getMinutes()).slice(-2),
						second = ("0" + time.getSeconds()).slice(-2);
					// 拼接
					var result = year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
					var that = this
					// 获取个人地址 和个人电话+提交订单
					uni.request({
						url: 'http://111.231.22.97:9000/getPersonAreaPhone',
						method: "GET",
						data: {
							username: uni.getStorageSync("userInfo").username
						},
						header: {
							"Authorization": uni.getStorageSync('token').token,
						},
						success(res) {
							// that.areaPer = res.data.data.areaPer,
							// that.phonePer = res.data.data.phone
							if (res.data.code == 200) {
								that.areaPer = res.data.data.areaPer,
									that.phonePer = res.data.data.phone,
									that.$nextTick(() => {
										console.log(that.areaPer, 'pppp')
										postShopPersonList({
											username: uni.getStorageSync("userInfo").username,
											shopNums: that.quantity,
											shopName: that.data.foodName,
											shopWorkNums: getwordOrder(),
											shopStatus: 0,
											shopPrice: that.data.foodPrice,
											orderTimes: result,
											shopTotalPrice: that.shopTotalPrice,
											newMoney: that.money - that.shopTotalPrice,
											areaPer: that.areaPer,
											phonePer: that.phonePer,
											formUser: that.data.formUser,
											images: that.data.img
										}).then(res => {
											if (res.code == 200) {
												toast('下单成功')
												setTimeout(() => {
													uni.navigateBack({
														delta: 1
													})
												}, 500)
											}
										})
									})
							} else {
								that.$refs.uToast.show({
									type: 'error',
									icon: false,
									title: '失败主题',
									message: "请检查地址信息",
								}, )
							}
						}
					})
					//



				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.List {
		width: 100vw;
		overflow: auto;

		.my {
			width: 80vw;
			margin: 1.5vh auto;
			padding: 3vw 0;
			background: #fff;
			border-radius: 15rpx;
			display: flex;
			box-shadow: 0px 5px 10px #888888;

			.left {
				width: 100%;

				.showName,
				.showPhone,
				.show {
					font-size: 28rpx;
					line-height: 32rpx;
					margin-left: 2vw;
					margin-right: 2vw;
				}
			}

			.right {
				width: 30%;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
	}

	.pages {
		width: 100%;
		height: 100vh;
		position: relative;
	}

	.Add {
		width: 100%;
		height: 10vh;
		position: absolute;
		bottom: 0;
		left: 0;
		background-color: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.Add>view {
		display: flex;
		align-items: center;
	}
</style>